package jy.game.components.item;


import java.util.ArrayList;
import java.util.List;

import jy.game.BasePojo;
import jy.game.JyRequire;
import jy.game.components.wuxue.JyTrigger;
import jy.game.components.wuxue.box.JySkillInstance;
import jy.game.components.wuxue.box.JySpecialSkillInstance;
import jy.game.tools.JyResourceManager;
import wx.xml.simpleframework.xml.Attribute;
import wx.xml.simpleframework.xml.ElementList;
import wx.xml.simpleframework.xml.Root;

@Root(name = "item")
public class JyItem extends BasePojo {

    @Attribute(name = "name") public String name;
    @Attribute public                String desc;
    @Attribute public                String pic;

    /**
     * <pre>
     * Costa,//0
     * Weapon,//1
     * Armor,//2
     * Accessories,//3
     * Book,//4
     * Mission,//5
     * SpecialSkillBook,//6
     * TalentBook,//7
     * Upgrade,//8
     * Special,//9
     * CanZhang,//10
     * SwitchGameScene//11
     * </pre>
     *
     * @see ItemType
     */
    @Attribute public int type;
    @Attribute public int level;


    //    public JyItemInstance Generate(boolean setRandomTrigger) {
//        JyItemInstance itemInstance = new JyItemInstance();
//        itemInstance.name = this.name;
//        if (setRandomTrigger) {
//            if (CommonSettings.MOD_KEY == 1) {
//                if (Tools.probabilityTest(0.1)) {
//                    itemInstance.AddRandomTriggers(4);
//                } else if (Tools.probabilityTest(0.2)) {
//                    itemInstance.AddRandomTriggers(3);
//                } else if (Tools.probabilityTest(0.4)) {
//                    itemInstance.AddRandomTriggers(2);
//                } else {
//                    itemInstance.AddRandomTriggers(1);
//                }
//            } else if (Tools.probabilityTest(0.0001)) {
//                itemInstance.AddRandomTriggers(16);
//            } else if (Tools.probabilityTest(0.01)) {
//                itemInstance.AddRandomTriggers(10);
//            } else if (Tools.probabilityTest(0.02)) {
//                itemInstance.AddRandomTriggers(9);
//            } else if (Tools.probabilityTest(0.06)) {
//                itemInstance.AddRandomTriggers(8);
//            } else if (Tools.probabilityTest(0.07)) {
//                itemInstance.AddRandomTriggers(7);
//            } else if (Tools.probabilityTest(0.08)) {
//                itemInstance.AddRandomTriggers(6);
//            } else if (Tools.probabilityTest(0.09)) {
//                itemInstance.AddRandomTriggers(5);
//            } else if (Tools.probabilityTest(0.1)) {
//                itemInstance.AddRandomTriggers(4);
//            } else if (Tools.probabilityTest(0.2)) {
//                itemInstance.AddRandomTriggers(3);
//            } else if (Tools.probabilityTest(0.4)) {
//                itemInstance.AddRandomTriggers(2);
//            } else {
//                itemInstance.AddRandomTriggers(1);
//            }
//        }
//        return itemInstance;
//    }
    @Attribute public                                    int                          price;
    @Attribute public                                    boolean                      drop;
    @Attribute public                                    String                       talent        = "";
    @Attribute public                                    String                       canZhangSkill;
    @Attribute(name = "cd") public                       int                          coolDown;
    @ElementList(name = "require", inline = true) public List<JyRequire>              requires      = new ArrayList<>();
    @ElementList(name = "trigger", inline = true) public List<JyTrigger>              triggers      = new ArrayList<>();

    @ElementList(name = "skills") public                 List<JySkillInstance>        skills        = new ArrayList<>();
    @ElementList(name = "special_skills") public         List<JySpecialSkillInstance> specialSkills = new ArrayList<>();

    static Builder builder() {
        Builder builder = new Builder();
        builder.value = new JyItem();
        return builder;
    }

    public static JyItem getItem(String name) {
        if (name.endsWith("残章")) {
            String text = name.replace("残章", "");
            return JyItem.builder()
                .name(name)
                .type(10).pic("物品.剑谱")
                .canZhangSkill(text)
                .desc("【稀有】神秘的武学残章，能够永久提高" + text + "的等级上限1级。\n注：本物品将被自动使用，提高全存档的该项武学等级上限。")
                .price(200)
                .build();
        }
        return JyResourceManager.get(JyItem.class, name);
    }

    // (get) Token: 0x060003E7 RID: 999 RVA: 0x00004219 File Offset: 0x00002419
    @Override public /*override*/ String getPK() {
        {
            return this.name;
        }
    }

    // (get) Token: 0x060003E8 RID: 1000 RVA: 0x00004221 File Offset: 0x00002421
    //[XmlIgnore]
    public String[] talents() {
        {
            return this.talent.split("#");
        }
    }

    static class Builder {
        JyItem value;

        JyItem build() {
            return value;
        }

        Builder name(String name) {
            this.value.name = name;
            return this;
        }

        Builder type(int type) {
            this.value.type = type;
            return this;
        }

        Builder pic(String pic) {
            this.value.pic = pic;
            return this;
        }

        Builder canZhangSkill(String skill) {
            this.value.canZhangSkill = skill;
            return this;
        }

        Builder desc(String desc) {
            this.value.desc = desc;
            return this;
        }

        Builder price(int price) {
            this.value.price = price;
            return this;
        }
    }
}
